package com.orangelife.mobile.confirmOrder.adapter;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.curry.orangelife.mobile.R;
import com.orangelife.mobile.buyFresh.biz.BuyFresh;
import com.orangelife.mobile.widget.GoodsDispatchPopupWindow.OnGoodsPopupWindowItemClickListener;

import java.util.List;

public class GoodsDispatchListViewAdapter extends BaseAdapter {

	private Context context;
	private List<String> list;
	private OnGoodsPopupWindowItemClickListener mListener;

	public GoodsDispatchListViewAdapter(Context context, List<String> list) {
		this.context = context;
		this.list = list;
	}

	/** 获得PopupWindowItem的监听器 */
	public void setListener(OnGoodsPopupWindowItemClickListener mListener) {

		this.mListener = mListener;
	}

	@Override
	public int getCount() {

		return list.size();
	}

	@Override
	public Object getItem(int position) {

		return list.get(position);
	}

	@Override
	public long getItemId(int position) {

		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		ViewHolder viewHolder = null;
		if (convertView == null) {
			convertView = LayoutInflater.from(context).inflate(
					R.layout.item_gv_buy_fresh, null);
			viewHolder = new ViewHolder();
			viewHolder.tvType = (TextView) convertView
					.findViewById(R.id.tvWeight);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		/* listview填数据 */

		viewHolder.tvType.setText(list.get(position).toString());
		final TextView tvTmp = viewHolder.tvType;
		final String strItemData = list.get(position);
		final int clickPositon = position;
		/* 这里是判断点击了哪个选项，并给相对应的项设置颜色和图片的 */
//		int spPosition = BuyFresh.getInstance().getSpTyprPosition();
//		if (spPosition == clickPositon) {
//			tvTmp.setTextColor(context.getResources().getColor(
//					R.color.TextOrange));
//		} else {
//			tvTmp.setTextColor(context.getResources().getColor(
//					R.color.TextBlack));
//		}
		/* llPopItem的点击监听事件，并将clickPositon, strItemData的值传递出去 */
		viewHolder.tvType.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				mListener.onPopupWindowItemClick(clickPositon, strItemData);

			}
		});

		return convertView;
	}

	static class ViewHolder {
		/** 搜索条件的值 */
		public TextView tvType;
		

	}

}
